{extends file="../home.html"}
{block name="title"}{$head_title}{/block}

{block name="css"}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/front/front_css/refresh_load.css?version={$version}"/>
<link href="__PUBLIC__/Css/front/css/channel_index.css?version={$version}" type="text/css" rel="stylesheet">
<style type="text/css">
body{

}
#load_wrapper{
	top:4rem;
}
.pindao .pd_list{
	padding: .75rem .6rem;
}
.pd_list li{
	margin-bottom: 0.75rem;
}
</style>
{/block}
{block name="content"}

	
	<div class="com_header">
		<a href="javascript:;" class="go_back"><i class="icon_back"></i></a>
		<form method="get" action="">
			<div class="search_input">
				<input type="text" placeholder="搜索帖子、频道、用户" value="{$kw}" name="kw" id="search">
				<i class="icon_x"></i>
			</div>
		</form>
	</div>
	<!-- 分类搜索 -->
	<div class="search_type">
		<div class="search_one active" data-type="tiezi">
			<span>帖子</span>
		</div>
		<div class="search_one" data-type="pindao">
			<span>频道</span>
		</div>
		<div class="search_one" data-type="people">
			<span>用户</span>
		</div>
	</div>
<div id="load_wrapper">
	<div id="scroller">
	<!-- 搜索结果是帖子 -->
	<div class="tiezi result_list">
		<ul class="tiezi_list">
			{foreach from=$search_list item=v}
			<li>
				<a href="/FrontChannel/post_detail/post_id/{$v.post_id}" class="native_go">
					<div class="user">
						<img src="{$v.post_user.headimgurl}" alt=""><span>{$v.post_user.nickname}</span>
					</div>
					<div class="text">
						<h3>{$v.title}</h3>
						<p>{$v.content}</p>
					</div>
				</a>
			</li>
			{/foreach}
		</ul>
	</div>
	<div class="pindao result_list" style="display: none">
		<ul class="pd_list">
			<!-- <li>
				<a href="/FrontChannel/post_list/channel_id/">
					<img src="/Public/Images/img/icon-hone-xuan-50@3x.png" alt="">
					<span class="channel_name">赞赏照片</span>
					<i class="level">Lv2</i>
					<span class="new_num">新帖567</span>
				</a>
			</li> -->
		</ul>
	</div>
	<!-- 用户 -->
	<div class="people result_list" style="display: none">
		<ul class="people_list">
			<!-- <li>
				<a href="javascript:;">
					<img src="/Public/Images/img/icon-hone-xuan-50@3x.png" alt=""><span>赞赏世界</span>
				</a>
			</li> -->
		</ul>
	</div>

	<div id="pullUp" {if !$search_list}style="display:none;"{/if}>
		<span class="pullUpIcon"></span><span class="pullUpLabel">上拉加载...</span>
	</div>

	</div>
</div>

	<!-- 无搜索结果显示 -->
<div class="no-cout" style="display: {if $kw && !$search_list}block{else}none{/if}">
		<img src="/Public/Images/img/icon_channel_nosearch@3x.png" alt="">
		<p>没找到你要的内容，看看下面的内容吧</p>
</div>

	<!-- {include file="../Index/nav.html"} -->


{/block}
{block name="js"}


<script type="text/javascript" src="__PUBLIC__/Js/front/iscroll.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/front/js/search_load.js"></script>
<script>
var total = parseInt('{$total}');
var firstRow = parseInt('{$firstRow}');
{literal}
	$('#search').on('input',function(){
		var ipt_val = $('#search').val();
		if(ipt_val){
			$('.icon_x').show()
		}else{
			$('.icon_x').hide()
		}
	})
    $('.icon_x').on('click',function(){
    	$('#search').val('');
    	$(this).hide()
    })

    $('.search_type .search_one').on('click',function(){
    	$(this).addClass('active').siblings().removeClass('active');
    	var type = $(this).data('type');
    	var result_div = $('.'+type);
    	console.log(result_div)
    	var kw = $('[name=kw]').val();
    	if(kw == ''){
    		return;
    	}
    	$.ajax({
    		url:'/FrontIndex/search',
    		type:'get',
    		data:{type:type, kw:kw},
    		beforeSend:function(){
    			// $('#loading').show();
    		},
    		success:function(r){
    			result_div.siblings('.result_list').hide().find('li').remove();
    			result_div.show();
    			// console.log(data);return;
    			var html = '';
    			var data = r.data;
    			if(data != null){
    					result_div.show().find('ul').html('');
    					if(type == 'tiezi'){
    						
							for (var i = 0; i < data.length; i++) {
	    						html += '<li>\
											<a href="/FrontChannel/post_detail/post_id/'+data[i].post_id+'">\
												<div class="user">\
													<img src="'+data[i].post_user.headimgurl+'" alt=""><span>'+data[i].post_user.nickname+'</span>\
												</div>\
												<div class="text">\
													<h3>'+data[i].title+'</h3>\
													<p>'+data[i].content+'</p>\
												</div>\
											</a>\
										</li>'
							}
    					}else if(type == 'pindao'){
    						for (var i = 0; i < data.length; i++) {
    							var rank_name = '';
    							if(data[i].user_channel_rank != ''){
    								rank_name += '<i class="level">'+data[i].user_channel_rank+'</i>'
    							}
	    						html += '<li>\
											<a href="/FrontChannel/post_list/channel_id/'+data[i].channel_id+'">\
												<img src="'+data[i].icon+'" alt="">\
												<span class="channel_name">'+data[i].channel_name+'</span>'
												+rank_name+
												'<span class="new_num">新帖'+data[i].new_tie+'</span>\
											</a>\
										</li>'
							}
    					}else if(type == 'people'){
    						for (var i = 0; i < data.length; i++) {
	    						html += '<li>\
											<a href="/FrontUserCenter/others_space/user_id/'+data[i].user_id+'">\
												<img src="'+data[i].headimgurl+'" alt=""><span>'+data[i].nickname+'</span>\
											</a>\
										</li>'
							}
    					}
    				total = parseInt(r.total);
    				num = 1;
    				$('.no-cout').hide();
					$('#load_wrapper').show();
					// $('#loading').hide();
					result_div.show().find('ul').append(html);
    			}else{
    				// $('#loading').hide();
    				$('.result_list').hide();
    				$('#load_wrapper').hide();
    				$('.no-cout').show();
    			}
    			setTimeout(function(){
                    myScroll.refresh();
                },500);
    		}
    	})

    })
</script>
{/literal}
{/block}